/*******************************************************************************
 * Copyright (c) 2014-6-8 @author <a href="mailto:iffiff1@hotmail.com">Tyler Chen</a>.
 * All rights reserved.
 *
 * Contributors:
 *     <a href="mailto:iffiff1@hotmail.com">Tyler Chen</a> - initial API and implementation
 ******************************************************************************/
package org.iff.infra.eventbus;

import java.util.concurrent.Executors;

import javax.inject.Named;

import org.iff.infra.util.Logger;

import com.google.common.eventbus.AsyncEventBus;

/**
 * @author <a href="mailto:iffiff1@hotmail.com">Tyler Chen</a> 
 * @since 2014-6-8
 */
@Named("IffEventBus")
public class IffEventBus {

	private static final AsyncEventBus eventBus = new AsyncEventBus("IFF",
			Executors.newFixedThreadPool(100));

	public IffEventBus() {
		eventBus.register(new DeadEventListener());
	}

	public void register(Object object) {
		eventBus.register(object);
	}

	public void unregister(Object object) {
		eventBus.unregister(object);
	}

	public void post(Object event) {
		if (event == null) {
			Logger.debug("Event is null.");
			return;
		}
		try {
			eventBus.post(event);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
